#-----------------------------------
# Name: Carter Noordsij
# Project Madlibs.py
# Period: 1
# Start Date: 9/18/2013
# Last Revision Date: 10/7/2013
# Version: 1.0.4
#----------------------------
import os

swearList = ["fuck",
			"bitch",
			"cunt",
			"ass",
			"cock",
			"nigger",
			"pussy"]
			
snakeList = ["asp",
			"cobra",
			"rattlesnake",
			"rattle snake",
			"rattler",
			"anaconda",
			"adder",
			"boa",
			"boa constrictor",
			"coral snake",
			"cottonmouth",
			"diamondback",
			"viper",
			"garter",
			"garter snake",
			"hognose",
			"keelback",
			"kingsnake",
			"krait",
			"mamba",
			"black mamba",
			"python",
			"sidewinder",
			"water snake"]

bgColor = '0'
txtColor = 'F'

def getMenuOption(maxOptions):
	option = ""
	goodOption = False
	while not goodOption:
		option = raw_input("Enter a number or S or Q> ")
		option = option.upper()
		if option == 'S':
			goodOption = True
		elif option == 'Q' :
			goodOption = True
		elif option == "":
			pass
		else:
			isNum = True
			for character in option:
				if character not in "0123456789":
					isNum = False
			if isNum:
				if int(option) <= 0:
					isNum = False
				elif int(option) > maxOptions:
					isNum = False
			if isNum:
				goodOption = True
			else:
				print "Please type a number!"
		if not goodOption:
			print "Invalid Choice, please try again. "
	return option

def menu():
	print "Welcome to Madlibs"
	print "Select your story:"
	print " [1] Shane Takes a Drive"
	print " [2] The Snake"
	print " [3] The Big Game"
	print " [S] Settings"
	print " [Q] Quit"
	option = getMenuOption(4)
	return option

def getWord(prompt):
	word = ""
	goodWord = False
	while not goodWord:
		word = raw_input(prompt)
		if word.lower() not in swearList:
			goodWord = True
		if word.isdigit():
			goodWord = False
		character = ["/", "*", "-", "+", "!", "@", "#", "$", "%", "^", "&", "(", ")"]
		if character in word:
			goodWord = False
		if goodWord == False:
			print "Enter a valid word"
	return word
	
def getAction(prompt):
	action = ""
	goodAction = False
	while not goodAction:
		action = raw_input(prompt)
		if action[-3:] == "ing":
			goodAction = True
		if goodAction == False:
			print "Enter a valid word: "
	return action

def getSnake(prompt):
	snake = ""
	goodSnake = False
	while not goodSnake:
		snake = raw_input(prompt)
		if snake.lower() in snakeList:
			goodSnake = True
		if goodSnake == False:
			print "Enter a valid word"
	return snake

def getNumber(prompt, min = "", max = ""):
		num = ""
		goodNumber = False
		while not goodNumber:
			num = raw_input(prompt)
			isNum = True
			for digit in num:
				if digit not in ".0123456789":
					isNum = False
			if isNum:
				if min != "":
					if float(num) < min:
						isNum = False
				if max != "":
					if float(num) > max:
						isNum = False
			if isNum:
				goodNumber = True
			else:
				print "Enter a valid number"
		return num
					
def getColor(prompt):
	colors = ["black",
			  "blue",
			  "green",
			  "bright white",
			  "light red",
			  "red",
			  "aqua",
			  "purple",
			  "yellow",
			  "white",
			  "gray",
			  "light blue",
			  "light green",
			  "light aqua",
			  "light purple",
			  "light yellow"]
	opt = ""
	goodColor = False
	while not goodColor:
		opt = raw_input(prompt)
		if opt.lower() in colors:
			goodColor = True
	if opt == "black":
		color = '0'
	elif opt == 'blue':
		color = '1'
	elif opt == 'green':
		color = '2'
	elif opt == 'bright white':
		color = 'F'
	elif opt == 'light red':
		color = 'C'
	elif opt == 'red':
		color = '4'
	elif opt == 'aqua':
		color = '3'
	elif opt == 'purple':
		color = '5'
	elif opt == 'yellow':
		color = '6'
	elif opt == 'white':
		color = '7'
	elif opt == 'gray':
		color = '8'
	elif opt == 'light blue':
		color = '9'
	elif opt == 'light green':
		color = 'A'
	elif opt == 'light aqua':
		color = 'B'
	elif opt == 'light purple':
		color = 'D'
	elif opt == 'light yellow':
		color = 'E'
	return color

def getSpeed(prompt):
	speed = ""
	goodSpeed = False
	while not goodSpeed:
		speed = raw_input(prompt)
		if len(speed) == 2:
			if speed[0] in "123456789":
				if speed[1] in "05":	
					goodSpeed = True
		else:
			print "Enter a valid number"
	return speed

def getTime(prompt):
		time = ""
		goodTime = False
		while not goodTime:
			time = raw_input(prompt)
			if len(time) == 1:
				if time[0] in "12345":
					goodTime = True
			else:
				print "Enter a valid number"
		return time

def getHour(prompt):
		hour = ""
		goodHour = False
		while not goodHour:
			hour = raw_input(prompt)
			if len(hour) == 1:
				if hour[0] in "123456789":
					goodHour = True
			else:
				print "Enter a valid number"
		return hour

def story1():
	car = getWord("Enter a car make and model: ")
	street = getWord("Enter the name of a street: ")
	speed = getSpeed("Enter a two digit number 10 or greater that ends in 0 or 5: ")
	day = getWord("Enter a day of the week: ")
	time = getTime("Enter an integer 1-5: ")
	speed2 = getSpeed("Enter a two digit number 10 or greater that ends in 0 or 5: ")
	object = getWord("Enter a large object that you might find outside: ")
	carpart = getWord("Enter some part of a car: ")
	hour = getHour("Enter an integer 1-9: ")
	story = "It was a cold, snowy winter night and Shane was cruising in his  "
	story += car + " down " + street + ". "
	story += "He was going a little fast, " + speed + " over to be exact. "
	story += "He also knew there were always cops on " + street + ", especially on " + day + " nights. "
	story += "But Shane was famous for his YOLOING, and this fact didn't faze him. "
	story += "Looking at his clock, he saw it was nearly " + time + " in the morning. "
	story += "It felt like he had been driving for " + hour + " hours, but it had really only been " + hour + " minutes. "
	story += "He nearly jumped out of his seat when he saw the blue lights flashing in his mirror."
	story += "His wheels began sliding all over the road as he tried to speed up another " + speed2 + " mph. "
	story += "Spinning out of control, his car did a full 360 on some black ice and he smashed straight into a(n) " + object + ". "
	story += "Luckily, he was fine except for a few bumps and bruises. "
	story += "His car, on the other hand, was not as fortunate. "
	story += "The " + carpart + " was completely smashed in from where it had hit the " + object + " and most of the windows were shattered."
	story += "He looked back and saw the cop making his over to his mangled car. "
	story += "How was he going to talk his way out of this one? "
	story += "THE END"
	print story

def story2():
	name = getWord("Enter a boy's name: ")
	snake = getSnake("Enter a species of snake: ")
	length = getNumber("Enter a number: ")
	lastname = getWord("Enter a last name: ")
	weapon = getWord("Enter an object: ")
	setting = getWord("Enter a biome: ")
	object = getWord("Enter some kind of container: ")
	animal = getWord("Enter an animal: ")
	action = getAction("Enter a verb ending in 'i-n-g': ")
	pastverb = getWord("Enter a verb in the past tense: ")
	story = "Once upon a time there was snake named " + name + ". "
	story += name + " was a huge " + snake + ". "
	story += "He was nearly " + length + " feet long. "
	story += "Sadly, " + name + " had no family. "
	story += "A farmer named Mr. " + lastname + " had killed them with a " + weapon + " when Bob was just a snakelet. "
	story += "Slithering through the " + setting + " one day, " + name + " heard hisses coming from Mr. " + lastname + "'s farm. "
	story += "He went to investigate and found a family of " + snake + "s trapped in a(n) " + object + ". "
	story += "He wanted to free them, but the " + object + " was being guarded by an evil " + animal + ". "
	story += "Just when he was going to slither away, he realized that he had never tried to fight a(n) " + animal + " before. "
	story += "He decided he would give it a try and he attacked, " + action + " the " + animal + " until it " + pastverb + ". "
	story += "The other " + snake + "s thanked him for freeing them they even offered to accept him into their own family. "
	story += name + " happily accepted and they lived happily ever after. "
	print story

def story3():
	name = getWord("Enter a boy's first name: ")
	hours = getNumber("Enter a number: ")
	car = getWord("Enter a car make and model: ")
	object = getWord("Enter an object: ")
	adjective = getWord("Enter an adjective: ")
	verb = getWord("Enter a verb: ")
	action = getAction("Enter a verb ending in 'i-n-g': ")
	color = getWord("Enter a color: ")
	color2 = getWord("Enter another color: ")
	objects = getWord("Enter an object (plural): ")
	story = "It was the night of the big game and " + name + " had that familiar feeling of butterflies in his stomach. "
	story += "He knew he still had " + hours + " hours before the game started, but he was nervous anyways. "
	story += "He was driving in his " + car + " on the way to the school, when all of a sudden, a huge " + object + " appeared in the sky. "
	story += "When we pulled over to take a closer look, he saw that it wasn't a(n) " + object + ", but instead, it was a(n) " + adjective + " alien spaceship. "
	story += "Before he had the chance to " + verb + ", the ship was hovering over his car and descending fast. "
	story += "A hatch began to open, " + color + " light spilled out of it onto him and his surroundings. "
	story += "The car slowly lifted off the ground was sucked up into the belly of the ship by the tractor beam. "
	story += name + " passed out from shock and woke up in transparent viewing container on the ship. "
	story += "There were aliens " + action + " all around him. "
	story += "They had egg-shaped " + color2 + " eyes and fingers that were as long as " + objects + ". "
	story += name + " realized he wasn't so anxious about the big game any more. "
	print story

def settings():
	txtColor = getColor("Enter Text Color: ")
	bgColor = getColor("Enter Backgound Color: ")
	if txtColor != bgColor:
		os.system("color " + bgColor + txtColor)
	
def run():
	choice = ""
	while choice != 'Q':
		choice = menu()
		if choice == '1':
			story1()
		elif choice == '2':
			story2()
		elif choice == '3':
			story3()
		elif choice == 'S':
			settings()
		elif choice == 'Q':
			print "Goodbye"
			os.system("color " + bgColor + txtColor)
			raw_input("Press enter to exit")
		else:
			print "Something terrible has happened...go yell at the programmer"
	
run()